package com.wu.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")
                // 通过.select()方法，去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.wu.controller"))
                .paths(PathSelectors.any())
                // 配置如何通过path过滤,即这里只扫描请求以/kuang开头的接口
                //.paths(PathSelectors.ant("/kuang/**"))
                //any() // 任何请求都扫描
                //none() // 任何请求都不扫描
                //regex(final String pathRegex) // 通过正则表达式控制
                //ant(final String antPattern) // 通过ant()控制
                .build().apiInfo(new ApiInfoBuilder()
                        .title("wustudy-->>Swagger")
                        .description("Swagger，详细信息......")
                        .version("2.0")
                        .contact(new Contact("wustudy","https://gitee.com/gdutwu","123456@163.com"))
                        .license("The Apache License")
                        .licenseUrl("https://gitee.com/gdutwu")
                        .build());
    }

    //如何配置多个分组？配置多个分组只需要配置多个docket即可
    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("wustudy1");
    }
    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("wustudy2");
    }
    @Bean
    public Docket docket3(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("wustudy3");
    }
}
